package com.chap13;

import com.chap13.util.Utils;

import java.util.Arrays;
import java.util.concurrent.ForkJoinPool;

/**
 * <p>
 * <code>Test</code>
 * </p>
 *
 * @author junbao3
 * TODO
 * @date 2023-04-12 8:31
 * Copyright (C) 2021 IFlyTek. All rights reserved.
 */
public class Test {
    public static void main(String[] args) {
        int[] ints = Utils.buildRandomIntArray(20000000);


        int processors = Runtime.getRuntime().availableProcessors();
        MergeSort mergeSort = new MergeSort(ints,processors);
        long start = System.currentTimeMillis();
        mergeSort.splitAndSort();
        long end = System.currentTimeMillis();
        System.out.println(end-start);



        int[] arrayToSortByMergeSort = Arrays.copyOf(ints,ints.length);
        MergeSortTask task = new MergeSortTask(arrayToSortByMergeSort,processors);
        ForkJoinPool forkJoinPool = new ForkJoinPool(processors);
        long start1 = System.currentTimeMillis();
        forkJoinPool.invoke(task);
        long end1 = System.currentTimeMillis();
        System.out.println(end1-start1);
    }
}
